package com.ysw.config;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryNTimes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName CurarorConfig
 * @Description TODO
 * @Author ysw
 * @Date 2022/5/10 22:51
 */
@Configuration
public class CuratorConfig {

    @Autowired
    private ZkConfig zkConfig;

    /**
     * CuratorFramework 连接配置
     * @return
     */
    @Bean(initMethod = "start")
    public CuratorFramework curatorFramework(){
        return CuratorFrameworkFactory.newClient(
                zkConfig.getConnectionString(),
                zkConfig.getSessionTimeOutMs(),
                zkConfig.getConnectionTimeOutMs(),
                new RetryNTimes(zkConfig.getRetryCount(),zkConfig.getElapsedTimeMs())
        );
    }
}